home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / dbdump.pl < prev    next >
Perl Script  |  1996-09-05  |  11KB  |  456 lines

  1. #!/net/tenerife/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17. $HOST = "localhost:7999";
  18. $HTML = ".wais/Catalog.html";
  19. $HOMEHTML = "SunSolutions/index.html";
  20.  
  21. #
  22. # use the libmi stuff
  23. #
  24.  
  25. use Mi;
  26.  
  27. $lastCategory = "";
  28. $lastSubCategory = "";
  29. $newchapter = 0;
  30.  
  31. ### Set up output directory
  32.  
  33. $outputDirectory = "/net/snl/cdware/CDware/.products/.wais/wais-src";
  34. umask(022);
  35. mkdir($outputDirectory, 0777);        # make an output directory for book    
  36. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  37. unlink(<*>);                # delete all existing files in the output directory
  38.  
  39. {
  40.    local($query,$num_col, @record);
  41.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  42.  
  43. ### the query
  44.  
  45. $query = "
  46. select  p.Product_id, p.SolCompatible,    
  47.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  48.     p.ProdShortDesc, p.ProdLongDesc,
  49.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  50.     p.ProdSpecHand,
  51.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  52.     v.VendorPostCode,
  53.     v.VendorState, v.VendorZip, v.VendorCountry,
  54.     v.VendorPhone1code, v.VendorPhone1,
  55.     v.VendorPhone2code, v.VendorPhone2,
  56.     v.VendorFaxCode, v.VendorFax,
  57.     v.VendorEmailCode, v.VendorEmail,
  58.     v.VendorURL
  59. from   Vendor v using(lock=table),
  60.        Assoc_ProdVend a using(lock=table),
  61.        Products p using(lock=table)
  62. where  a.ProdId = p.Product_id
  63. and    a.VendId = v.Vendor_id
  64. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  65. ;";
  66.  
  67. # where  p.Product_id < 100 -- use to limit
  68. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  69.  
  70. ### query the database
  71.  
  72.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  73.  
  74.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  75.  
  76.    print "  Query Sent\n";
  77.  
  78.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  79.  
  80.    print "  Got Results\n";
  81.  
  82.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  83.  
  84.    $num_col = Mi::column_count($row_desc);
  85.  
  86.    print "  Results Have $num_col Columns\n";
  87.  
  88.    $row_num = 0;
  89.    while ($row = Mi::next_row($db, \$error))
  90.    {
  91.     $row_num++;
  92.     print "   Processing row $row_num...\r";
  93.     foreach $col (0..$num_col-1)
  94.     {
  95.           Mi::value($row, $col, $colval, $retlen);
  96.           $record[$col] = $colval;
  97.     }
  98.  
  99. ### Fix the data
  100.  
  101. # map double occurrences of ' to single '
  102.  
  103.     foreach $count (2..12)
  104.     {
  105.         $record[$count] =~ s/\'\'/\'/g;
  106.     }
  107.  
  108. ### Trim trailing spaces
  109.     foreach $count (2..30)
  110.     {
  111.         $record[$count] =~ s/ *$//g;
  112.     }
  113.  
  114. ### Fix descriptions
  115.     $record[7] = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  116.         if ($record[7] eq "")
  117.         {
  118.                 $record[7] = $record[6];
  119.         }
  120.         &makeBullets();
  121.  
  122. ### Now print out the data for this product        
  123.  
  124.     $newchapter = 0;
  125.     if ($lastCategory ne $record[2])
  126.     {
  127.         chdir $outputDirectory || die "bad cd\n";
  128.         $newchapter = 1;
  129.         $outputChapterName = &fix_special($record[2]);
  130.         $outputChapterName = &makefilename($outputChapterName, 25);
  131.         mkdir($outputChapterName, 0777);
  132.         chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
  133.         unlink(<*>);
  134.         $lastCategory = $record[2];
  135.                 $subTOCname = $outputChapterName . ".html";
  136.                 open(subTOC, "> $subTOCname");
  137.                 &addsubTOCheader($record[2]);
  138.     }
  139.     if ($lastSubCategory ne $record[3])
  140.     {
  141.         if ($record[3] eq "")
  142.         {
  143.             $record[3] = "NoSubcategory";
  144.         }
  145.         if ($newchapter == 0)
  146.         {
  147.             chdir ".." || die "bad sub cd\n";
  148.         }
  149.         $outputSubchapterName = &fix_special($record[3]);
  150.         $outputSubchapterName = &makefilename($outputSubchapterName, 25);
  151.         mkdir($outputSubchapterName, 0777);
  152.         chdir $outputSubchapterName || die "Can't cd to $outputSubchapterName\n";
  153.         unlink(<*>);
  154.         $lastSubCategory = $record[3];
  155.                 $TOCname = $outputSubchapterName . ".html";
  156.                 open(TOC, "> $TOCname");
  157.                 &makeTOCheader($subTOCname, $record[2], $record[3]);
  158.                 chdir("..") || die "Can't cd to main category";
  159.                 &addsubTOC($record[3], $outputSubchapterName);
  160.                 chdir "$outputSubchapterName" || die "Can't cd to subcategory";
  161.     }
  162.  
  163.     $filename = &fix_special($record[4]);
  164.     $filename = &makefilename($filename, 25);
  165.     $filename .= ".html";
  166.     open(PRODUCT, ">$filename") || die "Can't open product $filename\n";
  167.         &makeproductheader($record[3], $outputChapterName . ".html");
  168.         &makeproduct();
  169.         &makeproducttail();
  170.         &addTOCinfo($filename, $record[4], $record[5]);
  171.         close PRODUCT;
  172.  
  173.     }
  174.  
  175.  
  176. # End of Product
  177.  
  178.    &makeTOCtail();
  179.    close TOC;
  180.    close subTOC;
  181.    Mi::close($db);
  182.  
  183.    print "Processed $row_num records\n";
  184. }
  185.  
  186.  
  187. #------------------------------------------------------------------
  188. # SUBROUTINES
  189. #------------------------------------------------------------------
  190.  
  191. sub makeBullets {
  192.  
  193.     local(@strings) = split(/\n/, $record[7]); 
  194.     local($bullet) = 0; 
  195.  
  196.     foreach $string (@strings)
  197.     {
  198.     if ($string =~ s/^--/<LI>/)
  199.     {
  200.         if ($bullet == 0)
  201.         {
  202.         $string =~ s/<LI>/<UL><LI>/;    
  203.         $bullet = 1;
  204.         }
  205.     }
  206.     else
  207.     {
  208.         if ($bullet == 1)
  209.         {
  210.         $string = "</UL>" . $string;
  211.         $bullet = 0;
  212.         }
  213.     }
  214.     }
  215.     $record[7] = join(/\n/, @strings);
  216.     if ($bullet == 1) # check for corner case
  217.     {
  218.          $record[7] .= "</UL>";
  219.     }
  220. }
  221.  
  222. sub makefilename {
  223.  
  224.         local(@strings) = split(/_/, @_[0]);
  225.     local($length) = @_[1];
  226.         local($new) = "";
  227.     local($first) = 1;
  228.  
  229.     foreach $string (@strings)
  230.     {
  231.     if ($first == 1)
  232.     {
  233.         $new .= $string;
  234.         $first = 0;
  235.     }
  236.     else
  237.     {
  238.         $new .= "_" . $string;
  239.     }
  240.     if (length($new) > $length)
  241.     {
  242.         return $new;
  243.     }
  244.     }
  245.     return $new;
  246. }
  247.  
  248. sub fix_special {
  249.  
  250.     local($text) = @_[0];
  251.  
  252.     $text =~ s/ /_/g;
  253.     $text =~ s/\!/_/g;
  254.     $text =~ s/\*/_/g;
  255.     $text =~ s/\//_/g;
  256.     $text =~ s/\&/_/g;
  257.     $text =~ s/\'/_/g;
  258.     $text =~ s/\`/_/g;
  259.     $text =~ s/#//g;
  260.     return $text;
  261. }
  262.  
  263. #------------------------------------------------------------------
  264. # makeproductheader
  265. #
  266. # subroutine makeproductheader creates header for every product file
  267.  
  268. sub makeproductheader {
  269.  
  270.     local($string) = @_[0];
  271.     local($filename) = @_[1];
  272.  
  273.     print PRODUCT <<PRODUCTHEADER;
  274. <html>
  275. <head>
  276. <title>Solaris - $string</title>
  277. </head>
  278. <body>
  279. <A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
  280. <A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF=../$filename><IMG SRC="/.wais/images/goto_back.gif"> Sub-category</A>
  281. <HR>
  282. <H2><A NAME=$record[3]>"$record[3]"</A></H2>
  283.  
  284. <HR>
  285. PRODUCTHEADER
  286. }
  287.  
  288. #------------------------------------------------------------------
  289. # makeproduct
  290. #
  291. # subroutine makeproduct creates info for every product file
  292.  
  293. sub makeproduct {
  294.  
  295.     local($source) = "No";
  296.     local($address) = $record[13] . " " . $record[14] . " " . $record[15];
  297.     local($address1) = $record[16] . ", " . $record[17] . $record[18] . " " . $record[19];
  298.     local($spec) = $record[12];
  299.     local($phone) = "";
  300.     local($phone1) = "";
  301.     local($fax) = "";
  302.     local($email) = "";
  303.     local($url) = "";
  304.     local($language) = "";
  305.     if ($record[11] ne "")
  306.     {
  307.     $language = "Language: " . $record[11] . "<BR>";
  308.     }
  309.     if ($record[22] ne "")
  310.     {
  311.         $phone = "Phone:  " . $record[21] . $record[22];
  312.         $phone1 = $record[23] . $record[24];
  313.     }
  314.     if ($record[26] ne "")
  315.     {
  316.         $fax = "Fax:    " . $record[25] . $record[26];
  317.     }
  318.     if ($record[28] ne "")
  319.     {
  320.         $email = "Email:  " . $record[27] . $record[28];
  321.     }
  322.     if ($record[29] ne "")
  323.     {
  324.         $url = "Url:    " . $record[29];
  325.     }
  326.     $address =~ s/^//g;
  327.     $address1 =~ s/^//g;
  328.     $spec =~ s/\[//g;
  329.     $spec =~ s/]//g;
  330.     $spec =~ s/^ * //g;
  331.     $spec =~ s/^,//g;
  332.     if ($spec eq "")
  333.     {
  334.         $spec = "None.";
  335.     }
  336.  
  337.     if ($phone1 ne "")
  338.     {
  339.         $phone .= "\n        " . $phone1;
  340.     }
  341.  
  342.     if ($record[10] eq "t" or $record[10] eq "T")
  343.     {
  344.         $source = "Yes";
  345.     }
  346.     print PRODUCT <<MAKEPRODUCT
  347. <H3><A NAME=$record[4]>$record[4]</A></H3>
  348. <H4><A NAME=$record[5]>$record[5]</A></H4>
  349. $record[7]<p>
  350. $language
  351. Source Avail: $source<BR>
  352. Product Special Handling: $spec<BR>
  353. <HR>
  354. <PRE>
  355. <B>$record[5]</B>
  356. $address
  357. $address1
  358. $record[20]<HR>
  359. $phone
  360. $fax
  361. $email
  362. $url
  363. </PRE>
  364. MAKEPRODUCT
  365. }
  366.  
  367. #------------------------------------------------------------------
  368. # makeproducttail
  369. #
  370. # subroutine makeproducttail creates tail for product file
  371.  
  372. sub makeproducttail {
  373.  
  374.     print PRODUCT <<MAKEPRODUCTTAIL
  375. </body>
  376. </html>
  377. MAKEPRODUCTTAIL
  378. }
  379.  
  380. #------------------------------------------------------------------
  381. # makeTOCheader
  382. #
  383. # subroutine MakeTOCheader prints header for each TOC
  384.  
  385. sub makeTOCheader {
  386.  
  387.     local($filename) = @_[0];
  388.     local($category) = @_[1];
  389.     local($subcategory) = @_[2];
  390.  
  391.     print TOC <<makeTOCheader
  392. <html>
  393. <title>Solaris - <A HREF="$filename">$subcategory</A> Products</title>
  394.  
  395. <A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
  396. <A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page </A>
  397. <A HREF="../$filename"><IMG SRC="/.wais/images/goto_back.gif"> Sub-category</A>
  398. <HR>
  399. <H1>Catalyst Solaris Products</H1>
  400. <H2>Product Listing</H2>
  401. <HR>
  402.  <h2><IMG SRC="/.wais/images/bullet_ball_red.gif"> <A HREF="../$filename">$subcategory</A></h2>
  403. <ul>
  404. makeTOCheader
  405. }
  406.  
  407. sub addsubTOCheader {
  408.  
  409.     local($category) = @_[0];
  410.  
  411.     print subTOC <<addsubTOCheader
  412. <title>Solaris - Networking</title>
  413.  
  414. <A HREF="http://$HOST/$HOMEHTML"><IMG SRC="/.wais/images/goto_home.gif"></A><HR>
  415. <A HREF="http://$HOST/$HTML"><IMG SRC="/.wais/images/goto_toc.gif"> Catalyst Catalog Search Page</A>
  416. <HR>
  417. <H1>Catalyst Solaris Products</H1>
  418. <H2>Sub-categories</H2>
  419. <HR>
  420. <H2><IMG SRC="/.wais/images/bullet_ball_blue.gif"> $category<H2>
  421. <UL>
  422. addsubTOCheader
  423.  
  424. }
  425.  
  426. sub makeTOCtail {
  427.  
  428.     print subTOC <<makeTOCtail
  429. </ul></html>
  430. makeTOCtail
  431. }
  432.  
  433. sub addsubTOC {
  434.  
  435.     local($subcategory) = @_[0];
  436.     local($subcategoryname) = @_[1];
  437.  
  438.     print subTOC <<addsubTOC
  439. <IMG SRC="/.wais/images/bullet_ball_red.gif"><A HREF="$subcategoryname/$subcategoryname.html"><STRONG>  $subcategory</A></STRONG></A><BR>
  440. addsubTOC
  441. }
  442.  
  443. sub addTOCinfo {
  444.  
  445.         local($filename) = @_[0];
  446.         local($product) = @_[1];
  447.         local($vendor) = @_[2];
  448.  
  449.     print TOC <<addTOCinfo
  450. <B>
  451. <IMG SRC="/.wais/images/bullet_ball_yellow.gif"> <A HREF="$filename">$product</A></B>
  452. <ul>
  453. $vendor</ul><p>
  454. addTOCinfo
  455. }
  456.